//
//  TranslationListCell.swift
//  GLUZSwift
//
//  Created by xyanl on 2025/3/13.
//  Copyright © 2025 考拉🐨. All rights reserved.
//

import UIKit
import Reusable
import Kingfisher

extension TranslationListCell: NibReusable {}

class TranslationListCell: BaseTableViewCell {

    @IBOutlet weak var markView: UIView!
    @IBOutlet weak var avatarImageView: UIImageView!
    @IBOutlet weak var countryImageView: UIImageView!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var chargeLabel: UILabel!
    @IBOutlet weak var stateView: UIView!
    
    @IBOutlet weak var ratingView: RatingStar!
    
    var model: TranslatorsModel? {
        didSet {
            guard let model = model else { return }
            if let uRl = URL(string: model.avatar) {
                avatarImageView.kf.setImage(with: uRl)
            }
            
            if LanguageManager.isLanguageZH {
                nameLabel.text = model.name
                chargeLabel.text = "服务价格:\(model.intentionScore)积分/分钟"
            } else {
                nameLabel.text = model.nameRu
                chargeLabel.text = "Цена услуги:\(model.intentionScore)б./мин"
            }
            
            stateView.backgroundColor = UIColor(hex: model.status == 0 ? "#FF010B": "#4CD964")
            
            if model.isSelected {
                markView.addRoundedCorners(radius: 10, width: 2, color: UIColor(hex: "#007AFF"))
            } else {
                markView.addRoundedCorners(radius: 10, width: 1, color: UIColor(hex: "#999999"))
            }
            
            
            ratingView.rating = CGFloat(model.rating)
            
            let countryModel = AreaCodeModel.country(model.country)
            countryImageView.image = countryModel.image.toImage
            
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()

        avatarImageView.addRoundedCorners(radius: 22)
        stateView.addRoundedCorners(radius: 5)
        
        ratingView.isEnable = false
        ratingView.style = .half
        ratingView.backgroundColor = .clear
        ratingView.imageLight = UIImage(named: "翻译星星实心")!
        ratingView.imageDark = UIImage(named: "翻译星星空心")!
        
    }

    
}
